package com.jsj.subway.ai.utils;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;

@Slf4j
@Configuration
public class WebMVCConfig extends WebMvcConfigurationSupport {

    @Value("${pdf.root.path:/opt/pdf/}")
    private String rootRoot;
    @Override
    public void addCorsMappings(CorsRegistry registry) {
        log.info("配置跨域。。。");
        registry.addMapping("/**")
                .allowedOriginPatterns("*")
                .allowedMethods("GET", "POST", "PUT", "DELETE")
                .allowedHeaders("*")
                .allowCredentials(true)
                .maxAge(3600)
                .exposedHeaders("*");
    }
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/pdf/**").addResourceLocations("file:" + this.rootRoot);
        //registry.addResourceHandler("/static/**").addResourceLocations("classpath:/static/", "classpath:/META-INF/resources/");
        registry.addResourceHandler("/statics/**").addResourceLocations("file:" + "/opt/statics/");
        super.addResourceHandlers(registry);
    }


}
